1. Field of the Invention
The invention relates generally to interfaces used by programs to control and respond to components of a computer system and more specifically to the interfaces used by programs to control and respond to hardware environments.
2. Description of the Prior Art
When all is said and done, what a computer program does is control and respond to hardware devices. When a user types a character on the keyboard, the program executing on the computer system responds to the input from the keyboard hardware by causing the computer system to execute instructions which in turn cause the display terminal to display the typed character. Because the computer program controls and responds to hardware devices, the instructions in the program vary depending on the kinds of hardware devices being used.
One example of this is the form of the instructions themselves: each kind of computer has a set of instructions defined for it, and a program which is to execute on that kind of computer must be written using that set of instructions. Another example is the kinds of peripheral devices in the computer system. A peripheral device is a device such as a keyboard, a display, a disk drive, or a printer that works with the computer but is separate from it. A program written for a system with one kind peripheral device will not work on a system that uses a different kind of peripheral device, even though both systems have a computer that executes the same instruction set. For example, a program written for one kind of keyboard will not work with another kind of keyboard.
From early on, programmers have taken measures to decrease the dependence of their programs on hardware. The general technique for doing this has been for the programs to deal with the hardware in logical rather than physical terms to the greatest extent possible. The problems posed by the different instruction sets employed by various computer systems have been solved by writing the programs in high-level languages, which deal in logical operations such as assignment of a value to a variable or branching according to the value of a variable rather than in the physical operations performed by a given computer system""s instruction set. A compiler program then automatically translates the program written in the high-level language into an equivalent program written in the given computer""s instruction set.
Compilers have not, however, been able to solve the problem of dealing with differing peripheral devices. That problem is dealt with at present by the computer system""s operating system. An operating system is a computer program that manages the hardware making up a computer system and presents the hardware to the applications programmer as a set of generic entities. The applications programmer thus writes code for a generic keyboard, display, or file system and the operating system deals with the peculiarities of the system""s actual keyboards, displays, and file systems. For example, from the point of view of the applications programmer, a keyboard is simply a source of character codes, and the operating system provides the applications programmer with a generic keyboard that is exactly that, while itself dealing with the peculiarities of the particular keyboards being used in the computer system.
FIG. 1 shows a typical computer system 101. Computer system 101 includes a processor 103, memory 111, and a number of peripheral devices 105(0 . . . n). Processor 103 and peripheral devices 105(0 . . . n) are coupled to memory 111 by bus 109, and can thus read data 112 from and write data 112 to memory 111. Processor 103 further reads instructions 114 from programs stored in memory 111 and executes them. Where the program involves peripheral devices, processor 103 responds to the instructions relevant to the peripheral devices by sending control signals to them. When something happens in a peripheral device that requires intervention of processor 103, the peripheral device sends an interrupt to processor 103. In response to the interrupt, processor 103 executes code in memory 111. For example, when a user strikes a key on a keyboard, an interrupt results whose associated code may cause processor 103 to put the character received from the keyboard into a predetermined location in memory for later use by a program that displays characters on a display device.
The programs in memory 111 include one or more applications programs 123, operating system 117, and BIOS 113, a low-level program that provides basic I/O services to operating system 117. BIOS 113, processor 103 and peripheral devices 105(0 . . . n) make up hardware environment 102 of system 101. The makers of hardware environment 102 generally provide a BIOS 113 suited for the environment they are providing.
Operating system 117 makes it possible for applications program 123 to ignore the peculiarities of peripheral devices 105(0 . . . n) and of the interrupts they provide to processor 103. Operating system 117 presents an operating system interface 121 to applications program 123 in which the facilities of computer system 101 appear as generic devices. Thus, a peripheral device 105(i) which is a keyboard appears to application program 123 simply as a source of characters. Operating system 117 is made up of hardware environment-independent code and data 118, which is not affected by the peculiarities of hardware environment 102, and hardware-dependent code and data 119, which is. Two important components of hardware-dependent code and data 119 are device drivers 120 and interrupt handlers 122. A device driver is a program whose code is dependent on the peculiarities of a given peripheral device 105(i), typically because it controls peripheral device 105(i). An interrupt handler is code which processor 103 executes in response to an interrupt from a given peripheral device 105(i). As one would expect, this code is also dependent on the peculiarities of the given peripheral device.
Compilers and operating systems together have made it possible for applications programs to be portable, that is, an application program written for a given operating system can be recompiled to run on any computer system that uses the operating system. However, as one would expect from the role of the operating system in dealing with the hardware environment, operating systems are not portable. Even after the code for an operating system has been recompiled so that it is made up of instructions belonging to processor 103""s instruction set, the hardware-dependent code and data 119 must be rewritten to deal with the new hardware environment 102. This process of rewriting the hardware-dependent code and data is termed porting the operating system to the hardware environment. Porting an operating system is difficult, slow, and requires an extensive knowledge of both the new hardware environment 102 and at least the hardware-dependent code and data portion of the operating system.
What is needed is a technique which permits many hardware environments to be presented to the operating system by means of a single generic interface, thereby making it possible to replace the hardware environment-dependent code in the operating system with code that is dependent on the single generic interface, rather than a particular hardware environment. It is an object of the present invention to provide such a technique.
The invention provides a generic interface layer which executes in a hardware environment and in turn provides a generic interface to the hardware environment to a program such as an operating system that uses the generic interface layer to control and respond to the hardware environment. As mentioned above, the hardware environment includes a number of devices and produces a number of different kinds of interrupts.
The generic interface layer is made up of executable code including driver code for the devices and interrupt handler code which is executed in response to the interrupts. When executed, the interrupt handler code performs callbacks to callback code in the program that is executing on the generic interface layer. The generic interface layer further includes a generic interface to the driver code which the program uses to execute the driver code. In a preferred embodiment, the generic interface is made up of software interrupts, with the program specifying a software interrupt and the generic interface layer responding thereto by executing the corresponding driver code.
Also implemented in the generic interface layer is a loader that will load and begin execution of any program that can execute on the generic interface layer. The loader is able to locate the program in a set of files accessible to the hardware environment, load the program into memory, and set up the hardware environment so that it begins executing the program. The generic interface layer further includes a debugger mode which permits a user of the generic interface layer to control execution of a program running on the generic interface layer.
The generic interface layer uses system clock interrupt code that is executed in response to a system clock interrupt in the hardware environment to coordinate execution of code that does parts of complex operations. Code that executes in the generic interface layer can register itself or other code belonging to the generic interface layer with the system clock interrupt code. When the system clock interrupt code executes in response to the system clock interrupt, it executes the registered code.
One use of this capability is to keep the program that is executing on the generic interface layer from being suspended while the generic interface layer performs an operation which may take considerable time. The operation of course begins with a call by the program being executed by the generic interface layer to a driver; the driver registers a program which performs a component of the operation with the system clock interrupt and returns, thereby permitting the program to continue execution. In response to the next system clock interrupt, the component program is executed; if it can run, it does so, if it cannot, it reregisters itself. It may also of course register a program for another component of the operation. When the operation has been completed, the last component does a callback to the program indicating the result of the operation.
The generic interface layer finally includes an implementation of a technique for managing an array having a fixed number of buffers (0 . . . n) for receiving LAN packets. The LAN packets are stored in a queue of the buffers, with the queue being made up of successive buffers in the array, with buffer (n) being succeeded by buffer (0). If buffer (i) is the head of the queue, buffer (ixe2x88x921) is always the only buffer in the array whose end-of-buffer bit is set. As the head of the queue moves in the array, the end-of-buffer bit moves with it.
Other objects and advantages will be apparent to those skilled in the arts to which the invention pertains upon perusal of the following Detailed Description and drawing, wherein: